package com.lgx.common.web.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期
 * 
 * @author acer
 *
 */
public class DateUtils {

	public static final String DATE_FORMAT_ZH = "yyyy年MM月dd日";
	
	public static final String DATE_FORMAT_D = "yyyy-MM-dd";
	
	public static final String DATE_FORMAT_T = "yyyy-MM-dd HH:mm:ss";
	
	/**
	 * 日期转字符
	 * 
	 * @param date 
	 * @param format 日期格式
	 * @return
	 */
	public static String dateToChar(Date date,String format)
	{
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}
	
	/**
	 * 字符转日期
	 * 
	 * @param date
	 * @param format 日期格式
	 * @return
	 */
	public static Date charToDate(String date,String format)
	{
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			return sdf.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 获取星期几
	 * 
	 * @param date
	 * @return
	 */
	public static String getDayWeek(Date date)
	{
		String[] weeks = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };  
        Calendar cal = Calendar.getInstance();  
        cal.setTime(date);  
        int dayinweek = cal.get(Calendar.DAY_OF_WEEK) - 1;  
        return weeks[dayinweek];  
	}
}
